﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Globalization;
using BulldogCMS.Core.Runtime.Modules;

namespace BulldogCMS.Core.Runtime
{
    public class RequestContext
    {
        public string CurrentControllerName
        {
            get;
            internal set;
        }

        public string CurrentActionName
        {
            get;
            internal set;
        }

        public string CurrentAreaName
        {
            get;
            internal set;
        }

        public string CurrentViewName
        {
            get;
            internal set;
        }

        public string CurrentLayoutName
        {
            get;
            internal set;
        }

        public Storage.Node CurrentNode
        {
            get;
            internal set;
        }

        public CultureInfo Language
        {
            get;
            set;
        }

        public Storage.Site CurrentSite
        {
            get;
            internal set;
        }

        internal Storage.StorageEditor CurrentStorageEditor
        {
            get;
            set;
        }

        private List<SelectedVersion> SelectedVersions = new List<SelectedVersion>();

        internal void SetSelectedVersion(string nodePath, string language, int versionNumber)
        {
            var selectedVersion = this.SelectedVersions.Where(p => p.NodePath == nodePath).FirstOrDefault();
            if (selectedVersion != null)
            {
                selectedVersion.Language = language;
                selectedVersion.VersionNumber = versionNumber;
            }
            else
            {
                this.SelectedVersions.Add(new SelectedVersion()
                {
                    Language = language,
                    NodePath = nodePath,
                    VersionNumber = versionNumber
                });
            }
        }

        internal SelectedVersion GetSelectedVersion(string nodePath)
        {
            return this.SelectedVersions.Where(p => p.NodePath == nodePath).FirstOrDefault();
        }

        internal void UnselectVersion(string nodePath)
        {
            this.SelectedVersions.RemoveAll(p => p.NodePath == nodePath);
        }

        #region Current Module

        public IModuleAreaProvider CurrentModuleAreaProvider
        {
            get;
            internal set;
        }

        #endregion

    }
}